package org.wyn.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.wyn.common.ResultType;
import org.wyn.mongodb.bean.Blog;
import org.wyn.mongodb.bean.UserDetail;
import org.wyn.mongodb.dao.impl.UserDetailDao;
import org.wyn.service.IBlogService;
import org.wyn.service.IHomeService;
import org.wyn.service.IProfileTabService;

import com.google.inject.Inject;
/**
 * 主页action
 * @author wyn
 *
 */
@Namespace("/home")
@ParentPackage("security")
public class HomeAction extends WynActionSupport {
	/**
	 * 去首页
	 * @return
	 */
	@Action(value="goHome",results = {@Result(name = SUCCESS, type = ResultType.FREEMARKER, location = "home.ftl")})
	public String goHome(){
		ud = userDetailDao.findOne("userName", getLoginUserName());
		List<String[]> recentVisitors = iProfileTabService.getRecentVisitors(getLoginUserName());
		getRequest().setAttribute("recentVisitors", recentVisitors);
		return SUCCESS;
	}
	/**
	 * 测试 可删除
	 * @return
	 */
	@Action(value="home_test",results = {@Result(name = SUCCESS, type = ResultType.FREEMARKER, location = "home_test.ftl")})
	public String home_test(){
		return SUCCESS;
	}
	/**
	 * 去"首页-日志"页面
	 * @return
	 */
	@Action(value="goblog",results = {@Result(name = SUCCESS, type = ResultType.FREEMARKER, location = "blog.ftl")})
	public String blog_test(){
		blogList = iBlogService.findBlogOfFriendAndSefl(getLoginUserName());
		return SUCCESS;
	}
	/**
	 * 发表状态
	 */
	@Action(value="publish_status",results = {@Result(type = ResultType.PLAIN_TEXT)})
	public void publishStatus(){
		iHomeService.publishStatus(getLoginUser().getUserName(), content);
	}
	@Inject
	private IHomeService iHomeService;
	@Inject
	private UserDetailDao userDetailDao;
	@Inject
	private IProfileTabService iProfileTabService;
	@Inject
	private IBlogService iBlogService;
	private List<Blog> blogList;
	private String content;
	private UserDetail ud;
	private static final long serialVersionUID = 1L;
	public IHomeService getiHomeService() {
		return iHomeService;
	}
	public void setiHomeService(IHomeService iHomeService) {
		this.iHomeService = iHomeService;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public UserDetailDao getUserDetailDao() {
		return userDetailDao;
	}
	public void setUserDetailDao(UserDetailDao userDetailDao) {
		this.userDetailDao = userDetailDao;
	}
	public UserDetail getUd() {
		return ud;
	}
	public void setUd(UserDetail ud) {
		this.ud = ud;
	}
	public IBlogService getiBlogService() {
		return iBlogService;
	}
	public void setiBlogService(IBlogService iBlogService) {
		this.iBlogService = iBlogService;
	}
	public List<Blog> getBlogList() {
		return blogList;
	}
	public void setBlogList(List<Blog> blogList) {
		this.blogList = blogList;
	}
	public IProfileTabService getiProfileTabService() {
		return iProfileTabService;
	}
	public void setiProfileTabService(IProfileTabService iProfileTabService) {
		this.iProfileTabService = iProfileTabService;
	}

}
